package top.mccat.raven.combatstatus.handler;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import top.mccat.raven.combatstatus.utils.MsgUtils;

/**
 * @author Distance
 * @date 2022/6/14
 */
public class CommandHandler implements CommandExecutor {
    private final JavaPlugin plugin;
    private MsgUtils msgUtils;

    public CommandHandler(JavaPlugin plugin, MsgUtils msgUtils) {
        this.plugin = plugin;
        this.msgUtils = msgUtils;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (sender instanceof Player){
            Player player = (Player) sender;
            if (player.hasPermission("combatstatus.admin")){
                switch (args[0]){
                    case "reload":
                    case "RELOAD":
                        plugin.reloadConfig();
                        msgUtils.sendToPlayer(player,"&c配置文件已重新载");
                        break;
                    default:
                        break;
                }
            }
        }
        return true;
    }

    public void setMsgUtils(MsgUtils msgUtils) {
        this.msgUtils = msgUtils;
    }
}
